package com.leyou.user.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @author LT
 * @version 1.0.0
 * @ClassName JwtProperties.java
 * @Description TODO
 * @createTime 2020年05月19日 01:56:00
 */

@Data
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {

    private String pubKeyPath;
    private PublicKey publicKey;

    private AppTokenPojo app = new AppTokenPojo();

    @Data
    public class AppTokenPojo{
        private Long id;         // 服务id
        private String password; // 微服务自己的密码
    }
    /**
     * 指定初始化方法（这个方法等到所有：@ConfigurationProperties(prefix = "ly.jwt")属性注入之后，才去加载）
     * @throws Exception
     */
    @PostConstruct
    public void initMethod() throws Exception {
        this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
    }

}